package reflect;

import reflect.annotations.AutoRunClass;
import reflect.annotations.AutoRunMethod;

import java.lang.reflect.Method;
import java.util.Scanner;

public class test2 {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        System.out.println("输入类名：");
        String className = sc.nextLine();
        Class aclass = Class.forName(className);
        Object o = aclass.newInstance();
        if (aclass.isAnnotationPresent(AutoRunClass.class)) {

            Method[] methods = aclass.getMethods();
            for (Method method : methods) {
                if (method.isAnnotationPresent(AutoRunMethod.class)) {
                    method.invoke(o);
                }
            }
        }else {
            System.out.println("该类没有被@AutoRunClass标注");
        }
    }
}
